<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>02 非空验证</title>
</head>
<body>
    <input type="text" name="" id="txt">
    <input type="button" value="提交" id="btn">
</body>
<script src="../common.js"></script>
<script>
    (function() {

        // trim(): 删除前后所有空格，返回新的字符串

        var txt = getid('txt');
        var btn = getid('btn');

        btn.onclick = function() {
            var num = txt.value;
            if (num.trim()) {
                // 非空
                alert('非空');
            } else {
                alert('空');
            }
        }
    })();
</script>
</html>